App({
  todos: [
    { text: 'Learning Javascript', completed: true },
    { text: 'Learning ES2016', completed: true },
    { text: 'Learning 支付宝小程序', completed: false },
  ],

  userInfo: null,

  //@崖鹰 调用云函数，直接获得登录信息
  getUserInfoCloudFunc(){
    return new Promise((resolve, reject) => {
      if (this.userInfo) resolve(this.userInfo);

    });
  },

  //@果敢 访问后端拿到登录信息
  getUserInfo() {
    return new Promise((resolve, reject) => {
      if (this.userInfo) resolve(this.userInfo);

      my.getAuthCode({
        scopes: ['auth_user'],
        success: authcode => {
          console.info(authcode);

          my.httpRequest({
            url: '云应用用户授权接口',
            method: 'POST',
            data: {
              authcode,
              production: 'AlipayJSAPI',
            },
            dataType: 'json',
            success: function(res) {
              resolve(res);
            },
            fail: function(res) {
              my.alert({content: 'fail'});
            }
          });
        },
        fail: () => {
          reject({});
        },
      });
    });
  },
});
